package org.frend.rpc;

import com.alibaba.dubbo.config.annotation.Service;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service(timeout = 1200000)
public class ProcessServiceImpl implements ProcessService {

    @Autowired
    private RepositoryService repositoryService;

    @Autowired
    private RuntimeService runtimeService;

    @Autowired
    private TaskService taskService;

    @Override
    public Deployment deploymentProcessDefinition(String name, String resource) {
        Deployment deployment = repositoryService.createDeployment().name(name).addClasspathResource(resource)
                .deploy();
        return deployment;
    }

    @Override
    public List<ProcessDefinition> queryCreateProcessDefinition() {
        List<ProcessDefinition> list =repositoryService.createNativeProcessDefinitionQuery().list();
        return list;
    }

    @Override
    public ProcessInstance startProcessInstanceByKey(String processDefinitionKey) {
        ProcessInstance processInstance =runtimeService.startProcessInstanceByKey(processDefinitionKey);
        return processInstance;
    }

    @Override
    public List<Task> getTaskAssignee(String assignee) {
        List<Task> list =taskService.createTaskQuery().taskAssignee(assignee).list();
        return list;
    }

}
